//      File name:main.c
//      Version:1.0
//      Date:2011-02-28
//      Project:
//      Copyright 2011 Giancarlo Martini <gm at giancarlomartini.it>
//      Linux master 2.6.32-5-686 #1 SMP Wed Jan 12 04:01:41 UTC 2011 i686 GNU/Linux

//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>



int main(int argc, char *argv[])
{
	struct stat buf;
pippo
	FILE *f;
	char cmd_line[1000];
	char tmp[1000],*p,lat[15],lon[15];
	int pos;

	if(argc < 2)
	{
		puts("Bad arguments number.!\nExamples:\nlatlonlauncher file_name\n");
		exit(0);
	}
	if(stat(argv[1],&buf) < 0)
	{
		printf("But, can you read, or exists:%s\nAre you sure? I exit!\n",argv[1]);
		exit(0);
	}

	printf("I will use:\n%s\n",argv[1]);

	f = fopen(argv[1],"r");
	/* Something bad ...*/
	if(f == NULL) {perror("I can't open config file");exit(1);}

	/* Retrieves file cmds */
	while(fgets(cmd_line, 999, f) != NULL)
	{
		// Field parser */
		/* 04/02/2011,22:03:51,188.126.70.166,188-126-70-166.cust.vpntunnel.org,SE,Sweden,Vastra Gotaland,Lane,58.4167,12.0167 */
		//sscanf(cmd_line,"%s,%s,%s,%s,%s,%s,%s,%s,%f,%f",tmp,tmp,tmp,tmp,tmp,tmp,tmp,tmp,&lat,&lon);
		p = strtok(cmd_line,",");
		pos = 0;
		while (p != NULL)
		{
			printf("Trovato a pos:%d %s\n",pos,p);
			p = strtok (NULL, ",");
			if(pos == 8) strcpy(lat,p);
			if(pos == 9) strcpy(lon,p);
			pos++;
		}

	}

  /* Start to read file */
  return EXIT_SUCCESS;
}
/*--------------------------------------------------------------------------------------------*/

